<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class CreateSystemSecurityTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
     /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('system_security', ['engine' => 'InnoDB', 'collation' => 'utf8_general_ci', 'comment' => '安全信息表' ,'id' => 'id' ,'primary_key' => ['id']]);
        $table->addColumn('buss_type', 'enum', ['values' => ['0','1','2','3']])
            ->addColumn('buss_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => false,'comment' => '业务id: 代理商id,商户id',])
            ->addColumn('is_google_auth_bind', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '谷歌验证,0未绑定,1已绑定',])
            ->addColumn('google_secret', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '谷歌密钥',])
            ->addColumn('login_security_type', 'enum', ['values' => ['1','2']])
            ->addColumn('pay_security_type', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '支付安全类型: 0无需验证,1仅支付密码验证,2仅谷歌验证,3支付密码+谷歌组合验证',])
            ->addColumn('password', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => '登录密码',])
            ->addColumn('pay_password', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => '支付密码',])
            ->addColumn('login_white_ip', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '登录IP白名单',])
            ->addColumn('login_black_ip', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '登录IP黑名单',])
            ->addColumn('pay_white_ip', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '支付IP白名单',])
            ->addColumn('pay_black_ip', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '支付IP黑名单',])
            ->addColumn('agentpay_white_ip', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '代付IP白名单',])
            ->addColumn('agentpay_black_ip', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '代付IP黑名单',])
            ->addColumn('ip_change_need_relogin', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '变更ip是否需要重新登录：0无需重新登录,1需重新登录',])
            ->addColumn('private_key', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => 'API私钥',])
            ->addColumn('created_at', 'timestamp', ['null' => false,'default' => 'CURRENT_TIMESTAMP','signed' => true,'comment' => '创建时间',])
            ->addColumn('updated_at', 'timestamp', ['null' => false,'default' => 'CURRENT_TIMESTAMP','signed' => true,'comment' => '更新时间',])
            ->addIndex(['buss_type','buss_id'], ['unique' => true,'name' => 'uni_busstype_bussid'])
            ->addIndex(['buss_id'], ['name' => 'buss_id'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $this->dropTable('system_security');
    }
    
}
